package com.chenglai.video.controller;

import com.chenglai.commonutils.common.Result;
import com.chenglai.commonutils.common.StatusCode;
import com.chenglai.video.pojo.VideoCategory;
import com.chenglai.video.pojo.VideoInfo;
import com.chenglai.video.service.VideoInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 类描述：
 *
 * @Author rxh
 * @Date 2023/11/16 8:33
 */
@RestController
@RequestMapping("/videoInfo/")
public class VideoInfoController {
    
    @Resource
    private VideoInfoService videoInfoService;

    /**
     * 获取文章列表
     *
     * @param page 页码
     * @param size 数量
     * @param shopId 门店id
     * @return
     */
    @PostMapping("getVideoInfoList")
    @ApiOperation(value = "获取文章列表")
    public Result getVideoInfoList(Integer page, Integer size, Integer shopId) {
        try {
            PageInfo pageInfo = videoInfoService.getVideoInfoList(page, size, shopId);
            return new Result(true, StatusCode.OK, "操作成功", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "操作失败");
        }
    }

    /**
     * 添加/修改文章
     * @param videoInfo 文章实体类
     */
    @PostMapping("editVideoInfo")
    @ApiOperation(value = "添加/修改文章")
    public Result editVideoCategory(VideoInfo videoInfo) {
        try {
            videoInfoService.editVideoInfo(videoInfo);
            return new Result(true, StatusCode.OK, "操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "操作失败");
        }
    }

    /**
     * 删除文章
     * @param videoId 文章id
     */
    @PostMapping("delVideoInfo")
    @ApiOperation(value = "删除文章")
    public Result delVideoCategory(Integer videoId) {
        try {
            videoInfoService.delVideoInfo(videoId);
            return new Result(true, StatusCode.OK, "操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "操作失败");
        }
    }

    /**
     * 修改排序
     * @param videoId 文章id
     * @param sort 排序
     */
    @PostMapping("updateSortByVideoId")
    @ApiOperation(value = "修改排序")
    public Result updateSortByVideoId(Integer videoId, Integer sort) {
        try {
            videoInfoService.updateSortByVideoId(videoId, sort);
            return new Result(true, StatusCode.OK, "操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "操作失败");
        }
    }

    /**
     * 文章详情
     * @param videoId 文章id
     */
    @PostMapping("detail")
    @ApiOperation(value = "文章详情")
    public Result detail(Integer videoId) {
        try {
            VideoInfo detail = videoInfoService.detail(videoId);
            return new Result(true, StatusCode.OK, "查询成功", detail);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "查询失败");
        }
    }

    /**
     * 查询所有文章信息包含分类信息
     *
     * @param shopId 门店id
     * @return
     */
    @PostMapping("videoAll")
    @ApiOperation(value = "查询所有文章信息包含分类信息")
    public Result videoAll(Integer shopId) {
        try {
            List<VideoCategory> list = videoInfoService.videoAll(shopId);
            return new Result(true, StatusCode.OK, "查询成功", list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "查询失败");
        }
    }



}
